﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading;

namespace FizzBuzz
{
    internal class CalculatorTest
    {
        public delegate int BinaryOperation(int a, int b);

        public void Run()
        {
            Calculator c = new Calculator();
            BinaryOperation b = c.Add;

            
            IAsyncResult asyncResult = b.BeginInvoke(5, 10, OnAddCompletion, null);

            Thread.Sleep(1000);
            
        }

        public void OnAddCompletion(IAsyncResult _result)
        {
            AsyncResult asyncResult = (AsyncResult) _result;
            BinaryOperation b = (BinaryOperation)asyncResult.AsyncDelegate;
            int result = 0;
            result = b.EndInvoke(asyncResult);

            Console.WriteLine("Result:{0}", result);
        }
    }

    internal class Calculator
    {
        public int Add(int a, int b)
        {
            return a + b;
        }

        public int Substract(int a, int b)
        {
            return a - b;
        }
    }

}